<template>
  <div>
    <el-divider>客户信息</el-divider>
    <el-form style="margin-left: 100px">
      <el-row type="flex" :gutter="20" align="middle">
        <el-col :span="6">
          <el-form-item label="业务来源">
            <el-select v-model="channelParentLevel" clearable filterable>
              <el-option v-for="item in clientList" :key="item.id" :label="item.businessName" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="客户名称" label-width="130px">
            <el-input v-model="channelName" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="0">
            <el-button type="primary" @click="addChannel">添加</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" :gutter="20" align="middle">
        <el-col :span="6">
          <el-form-item label="客户名称">
            <el-select v-model="branchParentLevel" clearable filterable>
              <el-option v-for="item in channelList" :key="item.id" :label="item.channelName" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="子集名称" label-width="130px">
            <el-input v-model="branchName" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="0">
            <el-button type="primary" @click="saveBranch">添加</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { clientBusinessNoPage, addChannel, addBranch, clientChannelNoPage } from '@/api/client'

export default {
  name: 'Index',
  data() {
    return {
      dictList: [],
      clientList: [],
      channelParentLevel: [],
      channelName: [],
      branchParentLevel: [],
      branchName: [],
      channelList: []
    }
  },

  created() {
    this.init()
  },

  methods: {
    init() {
      this.getClientsList()
      this.getChannelList()
    },
    addChannel() {
      addChannel(this.channelParentLevel, this.channelName).then(res => {
        this.$message({
          message: '添加成功',
          type: 'success'
        })
        this.$router.go(0)
      })
    },
    getClientsList() {
      clientBusinessNoPage().then(res => {
        this.clientList = res.data.list
      })
    },
    saveBranch() {
      addBranch(this.branchParentLevel, this.branchName).then(res => {
        this.$message({
          message: '添加成功',
          type: 'success'
        })
        this.$router.go(0)
      })
    },
    getChannelList() {
      clientChannelNoPage().then(res => {
        this.channelList = res.data.list
      })
    }
  }
}
</script>

<style scoped>

</style>
